/**
 *  *2010-6-17 上午11:41:13  add 
 */
package com.base.myproject.client.HR.setting;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BaseObject;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.tools.Tools;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Administrator
 *2011-09-15
 * cxghiu410@gmail.com
 */
public class HR_weekEnd_Setting  extends BaseJDBCPanel
{
	BaseComboBoxForm<BaseModelData> weekDay = new BaseComboBoxForm<BaseModelData>("code","name"," dictionary"," where type = 'weekDay'",true);
	public HR_weekEnd_Setting()
	{
		init();
	}
	public void init()
	{
		add(initWeigetx());
		registerMainStore(store);
		setdefault();
	}
	private Widget initWeigetx()
	{
		VerticalPanel vpanel = new VerticalPanel();
		vpanel.add(createGrid());
		return vpanel;
		
	}
	
	BaseStore<BusiObject> store = null;
	BaseStore<BusiObject> getStore(){
	if(store==null) 
	{
		createStore();
	}
	return store;}
	
	private void setdefault() {
		store.addDefault("type", "weekEnd");
	}

	BaseStore<BusiObject> createStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("code");
		type.getField("code").setType(String.class);
		type.addField("name");
		type.getField("name").setType(String.class);
		type.addField("type");
		type.getField("type").setType(String.class);
		type.addField("mark");
		type.getField("mark").setType(String.class);
		type.addField("department");
		type.getField("department").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("dictionary");
		info.setKeyname(new String[] { "icode"});
		info.setSql("select * from dictionary where type = 'weekEnd'");
		store = new BaseStore<BusiObject>(type, info); 
		return store;
	}
	

	BaseGrid<BaseObject> grid=null;
	BaseGrid<BaseObject> createGrid(){
		CheckBoxSelectionModel<BaseObject> cbs = new CheckBoxSelectionModel<BaseObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig C2 = new ColumnConfig("code", "编码", 150);
		C2.setRenderer(weekDay);
		C2.setEditor(weekDay.getCelEditor());
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("name", "名称", 150);
		C3.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C3);
		ColumnConfig C6 = new ColumnConfig("mark", "备注", 200);
		C6.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C6);
		

		ColumnModel cm = new ColumnModel(columns);
		grid = new BaseGrid<BaseObject>(getStore(), cm, true, true);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		grid.setSelectionModel(cbs);
		grid.setHeight(400);
		grid.setWidth(600);
		return grid;
		}
}